package io.dy.converter;

import io.dy.anno.Dy;
import io.dy.bo.AddressBO;
import io.dy.bo.StudentBO;
import io.dy.vo.AddressVO;
import io.dy.vo.StudentVO;
import org.mapstruct.*;
import org.mapstruct.factory.*;
import java.util.HashMap;
/**
 * @author : dmj
 * @date: 2024/6/3 10:28 上午
 * @description:
 */
@Mapper
public interface StudentConverter {

    StudentConverter INSTANCE = Mappers.getMapper(StudentConverter.class);


    @Mappings({
            @Mapping(target = "grade", source = "belongGrade"),
            @Mapping(target = "addressDetail", source = "address", qualifiedByName = "addressDetail")
    })
    StudentVO bo2vo(StudentBO studentBO);

    @Mappings({
            @Mapping(target = "grade", source = "belongGrade"),
            @Mapping(target = "addressDetail", expression = "java(studentBO.addressDetail(studentBO.getAddress()))")
    })
    StudentVO bo2vo_02(StudentBO studentBO);


    @Mappings({
            @Mapping(target = "grade", source = "belongGrade"),
            @Mapping(target = "addressDetail", source = "address", qualifiedBy = Dy.class)
    })
    StudentVO bo2vo_03(StudentBO studentBO);




//    @Mappings({
//            @Mapping(target = "code", source = "cityCode"),
//            @Mapping(target = "name", source = "cityName")
//    })
//    AddressVO addressBO2Vo(AddressBO addressBO);


    @AfterMapping
    default void bo2voAfterOperate(@MappingTarget StudentVO studentVO){
        studentVO.setBelongSchool(studentVO.getBelongSchool() + " dy");
    }

    @Named("addressDetail")
    default String addressDetail(AddressBO addressBO){
        if(addressBO == null){
            return "";
        }
        return addressBO.getCityName() + "@@" + addressBO.getCityCode();
    }

    @Dy
    default String addressDetail_02(AddressBO addressBO){
        if(addressBO == null){
            return "";
        }
        return addressBO.getCityName() + "@@" + addressBO.getCityCode();
    }

//    @Mappings({
//            @Mapping(source = "name", target = "name"),
//            @Mapping(source = "age", target = "age")
//    })
//    HashMap<String, Object> bo2Map(StudentBO studentBO);
}
